www.gusucode.com > VC++网络版的打字软件源程序-源码程序 > VC++网络版的打字软件源程序-源码程序\code\TypeSrv V2.0\LoginDlg.cpp

    //Download by http://www.NewXing.com
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "typesrv.h"
#include "LoginDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog
#include "QuestionSet.h"

CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLoginDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoginDlg)
	m_strQuestion = _T("");
	m_lTestTime = 10;
	//}}AFX_DATA_INIT
	m_lID				= 0;
	m_strQuestionInfo	= _T("");
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
	DDX_Control(pDX, IDC_TESTTIME, m_CtrlTestTime);
	DDX_Control(pDX, IDC_INPUT_LANGUAGE, m_CtrlInputLanguage);
	DDX_Control(pDX, IDC_LIST_QUESTION, m_ListQuestion);
	DDX_Text(pDX, IDC_QUESTION, m_strQuestion);
	DDX_Text(pDX, IDC_TESTTIME, m_lTestTime);
	DDV_MinMaxLong(pDX, m_lTestTime, 1, 300);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	//{{AFX_MSG_MAP(CLoginDlg)
	ON_NOTIFY(NM_CLICK, IDC_LIST_QUESTION, OnClickListQuestion)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_QUESTION, OnDblclkListQuestion)
	ON_CBN_SELCHANGE(IDC_INPUT_LANGUAGE, OnSelchangeInputLanguage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers



BOOL CLoginDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	m_ListQuestion.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);

	CQuestionSet* pSet=new CQuestionSet;
	m_ListQuestion.InsertColumn(0,"序号");
	m_ListQuestion.SetColumnWidth(0,40);
	m_ListQuestion.InsertColumn(1,"请选择试题");
	m_ListQuestion.SetColumnWidth(1,230);

	pSet->Open();
	pSet->MoveFirst();
	int nItem=0;
	CString strText;
	while(!pSet->IsEOF())
	{
		strText.Format("%d",nItem+1);
		m_ListQuestion.InsertItem(nItem,strText,0);
		m_ListQuestion.SetItemText(nItem,1,pSet->m_Info);
		m_ListQuestion.SetItemData(nItem,(DWORD)pSet->m_ID);
		nItem++;
		pSet->MoveNext();
	}
	pSet->Close();
	delete pSet;
	m_nInputLanguage=0;
	m_CtrlInputLanguage.SetWindowText("英文输入法");

	CTypeSrvApp* pApp=(CTypeSrvApp*)AfxGetApp();
	if(pApp->IsRegisterSofts())
	{
		m_CtrlTestTime.EnableWindow(TRUE);
	}
	else
	{
		m_CtrlTestTime.EnableWindow(FALSE);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLoginDlg::OnClickListQuestion(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int nItemSel=m_ListQuestion.GetSelectionMark();
	if(0>nItemSel)
	{
		return;
	}

	m_lID=(long)m_ListQuestion.GetItemData(nItemSel);

	CString strSQL;
	strSQL.Format("Select * From Question Where ID=%d",m_lID);
	CQuestionSet* pSet=new CQuestionSet;
	pSet->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);

	m_strQuestionInfo=pSet->m_Info;
	m_strQuestion=pSet->m_Text;

	if(((CTypeSrvApp*)AfxGetApp())->IsRegisterSofts())
	{
		m_nInputLanguage=pSet->m_Flag;
		switch(m_nInputLanguage)
		{
		case 0:
			m_CtrlInputLanguage.SetWindowText("英文输入法");
			m_lTestTime=m_strQuestion.GetLength()*2/60;
			break;
		case 1:
			m_CtrlInputLanguage.SetWindowText("智能ABC输入法");
			m_lTestTime=m_strQuestion.GetLength()*5/60;
			break;
		default:
			m_CtrlInputLanguage.SetWindowText("英文输入法");
			m_lTestTime=m_strQuestion.GetLength()*2/60;
		}
		
		if(m_lTestTime<5)
		{
			m_lTestTime=5;
		}
	}
	UpdateData(FALSE);

	pSet->Close();
	delete pSet;


	*pResult = 0;
}

void CLoginDlg::OnDblclkListQuestion(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;

	CDialog::OnOK();
}

void CLoginDlg::OnSelchangeInputLanguage() 
{
	// TODO: Add your control notification handler code here
	m_nInputLanguage=m_CtrlInputLanguage.GetCurSel( );
}